import mockApi from "@/api/mockApi";
import type {CandidateForm} from '@/types/req/candidateForm'
import type {CandidateQueryForm} from '@/types/req/candidateQueryForm'
import type {Candidate} from '@/types/resp/candidate'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class candidateApi {
  static candidates: Candidate[] = [
    {"id":1,"username":"wangqiang","name":"王强","password":"wangqiang789","gender":1,"birthDate":dayjs("1988-05-28"),"contactPhone":"13712345678","email":"wangqiang@bluesky-env.com","province": "31", "provinceName": "上海市", "city": "3101", "cityName": "上海市", "area": "310115", "areaName": "浦东新区","address":"张江高科技园区456号","createTime":"2024-01-20 22:24:09","modifyTime":"2024-08-10 22:24:09"},
    {"id":2,"username":"chenjing1","name":"陈静","password":"chenjing123","gender":2,"birthDate":dayjs("1991-05-01"),"contactPhone":"13687654321","email":"chenjing@bluesky-env.com","province": "31", "provinceName": "上海市", "city": "3101", "cityName": "上海市", "area": "310115", "areaName": "浦东新区","address":"张江高科技园区789号","createTime":"2024-08-25 22:24:09","modifyTime":"2024-12-31 22:24:09"},
    {"id":3,"username":"zhangwei1","name":"张伟","password":"zhangwei123","gender":1,"birthDate":dayjs("1990-06-23"),"contactPhone":"13812345678","email":"zhangwei@greenfarm.com","province": "44", "provinceName": "广东省", "city": "4403", "cityName": "深圳市", "area": "440305", "areaName": "南山区", "address": "科技园南区1号","createTime":"2024-10-24 22:24:09","modifyTime":"2024-06-25 22:24:09"},
    {"id":4,"username":"linana123","name":"李娜","password":"lina456","gender":2,"birthDate":dayjs("1992-02-14"),"contactPhone":"13987654321","email":"lina@sunshine-tech.com","province": "11", "provinceName": "北京市", "city": "1101", "cityName": "北京市", "area": "110108", "areaName": "海淀区","address":"中关村大街1号","createTime":"2024-08-10 22:24:09","modifyTime":"2024-10-05 22:24:09"},
    {"id":5,"username":"liuyang","name":"刘洋","password":"liuyang456","gender":1,"birthDate":dayjs("1989-02-26"),"contactPhone":"13512345678","email":"liuyang@bluesky-env.com","province": "31", "provinceName": "上海市", "city": "3101", "cityName": "上海市", "area": "310115", "areaName": "浦东新区","address":"张江高科技园区101号","createTime":"2024-06-08 22:24:09","modifyTime":"2024-05-13 22:24:09"}
  ]

  static async save (candidateForm: CandidateForm): Promise<Result<void>> {
    console.log('candidateApi save params', candidateForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (candidateQueryForm: CandidateQueryForm): Promise<Result<Page<Candidate>>> {
    console.log('candidateApi find params', candidateQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(candidateApi.candidates)
    return response.data
  }

  static async findById (id: number): Promise<Result<Candidate>> {
    console.log('candidateApi findById id', id)
    let target = {}
    for (const a of candidateApi.candidates) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Candidate> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('candidateApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
